package com.hrms.controller;

import com.hrms.common.AjaxResult;
import com.hrms.common.BaseController;
import com.hrms.domain.Department;
import com.hrms.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/admin/department")
public class DepartmentController extends BaseController {
    @Autowired
    private DepartmentService departmentService;

     // 查询部门列表
    @GetMapping("/list")
    public AjaxResult list(Department department){
        List<Department> list = departmentService.selectDepartmentList(department);
        return success(list);
    }

    //获取部门详细信息
    @GetMapping(value = "/{deptNo}")
    public AjaxResult getInfo(@PathVariable("deptNo") Long deptNo){
        return success(departmentService.selectDepartmentByDeptNo(deptNo));
    }

    //新增部门
    @PostMapping
    public AjaxResult add(@RequestBody Department department){
        department.setCreateTime(new Date());
        department.setModifyTime(new Date());
        return toAjax(departmentService.insertDepartment(department));
    }

    //修改部门
    @PutMapping
    public AjaxResult edit(@RequestBody Department department){
        return toAjax(departmentService.updateDepartment(department));
    }

    //删除部门
    @DeleteMapping("/{deptNos}")
    public AjaxResult remove(@PathVariable Long[] deptNos){
        return toAjax(departmentService.deleteDepartmentByDeptNos(deptNos));
    }
}
